$.ajax({
	type: "get",
	url: "../getConstellation.json",
	async: true,
	data: {
		serkey: "",
		dates: "2016-3-18",
		type: "today"
	},
	beforeSend:function(){
		refresh();
	},
	complete:function(){
		$("#foo").css("display","none");
	},
	dataType: "json",
	success: function(rsp) {
		console.log(rsp);
		$(".constellation_name").html(rsp.result.data[0].name);
		$(".whole-fortune li").eq(0).html('<b>综合运势：</b>' + transform_num(rsp.result.data[1].all));
		$(".whole-fortune li").eq(1).html('<b>财运指数：</b>' + transform_num(rsp.result.data[1].money));
		$(".whole-fortune li").eq(2).html('<b>健康指数：</b>' + transform_num(rsp.result.data[0].health));
		$(".whole-fortune li").eq(3).html('<b>工作指数：</b>' + transform_num(rsp.result.data[0].work));
		$(".whole-fortune li").eq(4).html('<b>爱情指数：</b>' + transform_num(rsp.result.data[0].love));
		$(".whole-fortune li").eq(5).html('<b>幸运颜色：</b>' + rsp.result.data[0].color);
		$(".whole-fortune li").eq(6).html('<b>速配星座：</b>' + rsp.result.data[0].qfriend);
		$(".whole-fortune li").eq(7).html('<b>幸运数字：</b>' + rsp.result.data[0].number);

		//console.log(transform_num(""))
		myscroll.refresh();
	}
});

function transform_num(para) {
	para = para.split("%")[0];
	var num = "";
	var kong_str = "";
	var shi_str = "";
	var str = "";
	if (para == "undefined" || para == 0) {
		num = 0;
	} else if (para > 0 && para <= 20) {
		num = 1;
	} else if (para > 20 && para <= 40) {
		num = 2;
	} else if (para > 40 && para <= 60) {
		num = 3;
	} else if (para > 60 && para <= 80) {
		num = 4;
	} else {
		num = 5;
	}

	for (var i = 0; i < num; i++) {
		kong_str += '<span><img src="../img/consellation-img/start1.png" alt=""/></span>';
	}
	for (var i = 0; i < (5 - num); i++) {
		shi_str += '<span><img src="../img/consellation-img/start2.png" alt=""/></span>';
	}
	str = kong_str + shi_str;
	return str;
}

function refresh(){
	var opts = {
		lines: 10, // 个数
		length: 13, // 长度
		width: 8, // 宽度
		radius: 20, // 圆周
		corners: 1, // Corner roundness (0..1)
		rotate: 0, // The rotation offset
		direction: -1, // 1: clockwise, -1: counterclockwise
		color: '#000', // #rgb or #rrggbb or array of colors
		speed: 1, // Rounds per second
		trail: 60, // Afterglow percentage
		shadow: false, // Whether to render a shadow
		hwaccel: false, // Whether to use hardware acceleration
		className: 'spinner', // The CSS class to assign to the spinner
		zIndex: 2e9, // The z-index (defaults to 2000000000)
		top: 'auto', // Top position relative to parent in px
		left: 'auto' // Left position relative to parent in px
	};
	var target = document.getElementById('foo');
	var spinner = new Spinner(opts).spin(target);
}